Plot and Inference

library(ggplot2)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
baggagecomplaints <- read.csv("~/Downloads/baggagecomplaints.csv")

baggageUnited <- baggagecomplaints %>%
  filter(Airline == "United")

united_ts <- ts(baggageUnited$Baggage, start = c(2004, 1), end = c(2010,12), frequency = 12)
plot(united_ts, main = "Monthly Complaints (United Airlines)", xlab = "Year", ylab = "Complaints")

baggageAmerican <- baggagecomplaints %>%
  filter(Airline == "American Eagle")

american_ts <- ts(baggageAmerican$Baggage, start = c(2004, 1), end = c(2010,12), frequency = 12)
plot(american_ts, main = "Monthly Complaints (American Eagle)", xlab = "Year", ylab = "Complaints")

baggageHawaiian <- baggagecomplaints %>%
  filter(Airline == "Hawaiian")

hawaiian_ts <- ts(baggageHawaiian$Baggage, start = c(2004, 1), end = c(2010,12), frequency = 12)
plot(hawaiian_ts, main = "Monthly Complaints (Hawaiian)", xlab = "Year", ylab = "Complaints")

baggageUnited <- baggageUnited %>% mutate(Airline = "United")
baggageAmerican <- baggageAmerican %>% mutate(Airline = "American Eagle")
baggageHawaiian <- baggageHawaiian %>% mutate(Airline = "Hawaiian")

combined_baggage <- bind_rows(baggageUnited, baggageAmerican, baggageHawaiian)

ggplot(combined_baggage, aes(x = as.Date(paste(Year, Month, "1", sep = "-")), y = Baggage, color = Airline)) +
  geom_line(linewidth = 1) +
  labs(title = "Monthly Baggage Complaints by Airline", x = "Year", y = "Complaints") +
  theme_minimal() +
  scale_color_manual(values = c("blue", "red", "green"))

ggplot(combined_baggage, aes(x = as.Date(paste(Year, Month, "1", sep = "-")), y = Baggage)) +
  geom_line(aes(color = Airline), linewidth = 1) +
  facet_wrap(~Airline, scales = "free_y") + # Facet by airline
  labs(title = "Monthly Baggage Complaints by Airline", x = "Year", y = "Complaints") +
  theme_minimal() +
  scale_color_manual(values = c("blue", "red", "green"))

# Aggregate total baggage complaints by Year and Airline
baggage_by_year <- baggagecomplaints %>%
  group_by(Year, Airline) %>%
  summarise(Total_Baggage_Complaints = sum(Baggage, na.rm = TRUE))
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
ggplot(baggage_by_year, aes(x = factor(Year), y = Total_Baggage_Complaints, fill = Airline)) +
  geom_bar(stat = "identity", position = "dodge") +  # Dodge separates bars by airline
  theme_minimal() +
  labs(
    title = "Total Baggage Complaints by Airline and Year",
    x = "Year",
    y = "Total Baggage Complaints",
    fill = "Airline"
  ) +
  scale_fill_manual(
    values = c("American Eagle" = "#FF9999", "Hawaiian" = "#99CCFF", "United" = "#FFCC99")
  ) +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

United Airline

American Eagle Airline

Hawaiian Airline

united_window <- window(united_ts, start = c(2007, 1), end = c(2010,12), frequency = 12)
american_window <- window(american_ts, start = c(2007, 1), end = c(2010,12), frequency = 12)
hawaiian_window <- window(hawaiian_ts, start = c(2007, 1), end = c(2010,12), frequency = 12)
par(mfrow = c(1, 3)) 
plot(united_window, main = "Monthly Complaints United Airlines", 
     xlab = "Year", ylab = "Complaints", col = "green")
plot(american_window, main = "Monthly Complaints American Eagle", 
     xlab = "Year", ylab = "Complaints", col = "blue")
plot(hawaiian_window, main = "Monthly Complaints Hawaiian", 
     xlab = "Year", ylab = "Complaints", col = "red")

summary(united_window)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    8597   14256   18340   20315   25778   41787
summary(american_window)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    7052    9537   11576   13393   15664   26213
summary(hawaiian_window)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1076    1318    1578    1729    2065    2791

United Airlines

American Eagle

Hawaiian Airlines

par(mfrow = c(1, 3)) 

boxplot(united_window, main = "Monthly Complaints United Airlines")
boxplot(american_window, main = "Monthly Complaints American Eagle")
boxplot(hawaiian_window, main = "Monthly Complaints Hawaiian Airlines")

acf(united_window, main = "ACF: United Airlines", col = "green", lwd = 2)

acf(american_window, main = "ACF: American Eagle", col = "blue", lwd = 2)

acf(hawaiian_window, main = "ACF: Hawaiian Airlines", col = "red", lwd = 2)

United Airlines

American Eagle

Hawaiian Airlines

united_decomp <- decompose(united_window)
american_decomp <- decompose(american_window)
hawaiian_decomp <- decompose(hawaiian_window)
plot(united_decomp)

plot(american_decomp)

plot(hawaiian_decomp)

Accuracy Measures

Going with MAPE as it measures the accuracy of a forecast model as a percentage and easy to interpret.

Forecasting Model

par(mfrow = c(1, 3))

united_naive <- naive(united_window, h = 12)
plot(united_naive, main = "Naive Forecast: United Airlines",
     xlab = "Year", ylab = "Complaints", col = "green")

american_naive <- naive(american_window, h = 12)
plot(american_naive, main = "Naive Forecast: American Eagle",
     xlab = "Year", ylab = "Complaints", col = "blue")

hawaiian_naive <- naive(hawaiian_window, h = 12)
plot(hawaiian_naive, main = "Naive Forecast: Hawaiian Airlines",
     xlab = "Year", ylab = "Complaints", col = "red")

par(mfrow = c(1, 1))

Naive Model: The simplest model, forecasting that future values will be the same as the last observed value. The forecasted line is constant and flat for the next 12 months. This model is simple and works well when no clear trend or seasonality, though it may not be very accurate for time series data with trends or seasonal patterns

Residual Analysis

residuals_naive_united <- residuals(united_naive)
fitted_naive_united <- fitted(united_naive)

residuals_naive_american <- residuals(american_naive)
fitted_naive_american <- fitted(american_naive)

residuals_naive_hawaiian <- residuals(hawaiian_naive)
fitted_naive_hawaiian <- fitted(hawaiian_naive)

par(mfrow = c(1, 3)) 
plot(residuals_naive_united, main = "United Airlines (Naive Model)", 
     ylab = "Residuals", xlab = "Time",col ='green')
plot(residuals_naive_american, main = "American Eagle Airlines (Naive Model)", 
     ylab = "Residuals", xlab = "Time", col ='blue')
plot(residuals_naive_hawaiian, main = "Hawaiian Airlines (Naive Model)", 
     ylab = "Residuals", xlab = "Time", col= 'red')

hist(residuals_naive_united, main = "United Airlines (Naive Model)", xlab = "Residuals")
hist(residuals_naive_american, main = "American Eagle Airlines (Naive Model)", xlab = "Residuals")
hist(residuals_naive_hawaiian, main = "Hawaiian Airlines (Naive Model)", xlab = "Residuals")

ggplot(data = NULL, aes(x = fitted_naive_united, y = residuals_naive_united)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: United Airlines",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = NULL, aes(x = fitted_naive_american, y = residuals_naive_american)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: American Eagle ",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = NULL, aes(x = fitted_naive_hawaiian, y = residuals_naive_hawaiian)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: Hawaiian Airlines",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

## Actual Vs Residual
ggplot(data = NULL, aes(x = united_window, y = residuals_naive_united)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: United Airlines",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = NULL, aes(x = american_window, y = residuals_naive_american)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: American Eagle ",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = NULL, aes(x = hawaiian_window, y = residuals_naive_hawaiian)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: Hawaiian Airlines",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

united_sa <- meanf(united_window, h=12)
american_sa <- meanf(american_window,  h=12)
hawaiian_sa <- meanf(hawaiian_window,  h=12)
par(mfrow = c(1, 3)) 

plot(united_sa, main = "United Airlines SMA", xlab = "Year", ylab = "Complaints")
plot(american_sa, main = "American Eagle SMA", xlab = "Year", ylab = "Complaints")
plot(hawaiian_sa, main = "Hawaiian Airlines SMA", xlab = "Year", ylab = "Complaints")

Simple Average Model: This forecasts using the mean of all historical observations. It shows the flat line for future even if there is a trend or seasonality.

united_ma <- ma(united_window, order = 3)
american_ma <- ma(american_window, order = 3)
hawaiian_ma <- ma(hawaiian_window, order = 3)

par(mfrow = c(1, 3)) 

plot(united_window, main = "United Airlines MA", xlab = "Year", ylab = "Complaints")
lines(united_ma, col = "red", lwd = 2)

plot(american_window, main = "American Eagle MA", xlab = "Year", ylab = "Complaints")
lines(american_ma, col = "red", lwd = 2)

plot(hawaiian_window, main = "Hawaiian Airlines MA", xlab = "Year", ylab = "Complaints")
lines(hawaiian_ma, col = "red", lwd = 2)

par(mfrow = c(1, 1))

Moving Average

United Airlines The moving average smooths out the fluctuations, highlighting the downward trend in complaints over time.

American Eagle The moving average closely follows the data, reflecting smoother declines with smaller fluctuation.

Hawaiian Airlines The moving average shows how stable Hawaiian Airlines is compared to the other airlines, with minimal fluctuations.

ets_united <- ets(united_window)
ets_american <- ets(american_window)
ets_hawaiian <- ets(hawaiian_window)

par(mfrow = c(1, 3))

plot(forecast(ets_united, h = 12), main = "ETS Forecast: United Airlines", xlab = "Year", ylab = "Complaints")

plot(forecast(ets_american, h = 12), main = "ETS Forecast: American Eagle", xlab = "Year", ylab = "Complaints")

plot(forecast(ets_hawaiian, h = 12), main = "ETS Forecast: Hawaiian Airlines", xlab = "Year", ylab = "Complaints")

par(mfrow = c(1, 1))

ETS Model

United Airlines

American Eagle

Hawaiian Airlines

summary(ets_united)   
## ETS(M,A,M) 
## 
## Call:
## ets(y = united_window)
## 
##   Smoothing parameters:
##     alpha = 0.3861 
##     beta  = 1e-04 
##     gamma = 2e-04 
## 
##   Initial states:
##     l = 33212.6596 
##     b = -422.8288 
##     s = 1.4633 0.6829 0.8277 0.7377 1.2025 1.0863
##            1.2161 0.8933 0.827 1.0044 0.9166 1.1422
## 
##   sigma:  0.121
## 
##      AIC     AICc      BIC 
## 942.9181 963.3181 974.7285 
## 
## Training set error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE      ACF1
## Training set -111.5725 2197.537 1593.736 -1.010138 7.813287 0.2950907 0.3705239
summary(ets_american)   
## ETS(M,Ad,M) 
## 
## Call:
## ets(y = american_window)
## 
##   Smoothing parameters:
##     alpha = 0.5059 
##     beta  = 1e-04 
##     gamma = 1e-04 
##     phi   = 0.962 
## 
##   Initial states:
##     l = 24352.5504 
##     b = -488.4151 
##     s = 1.3272 0.7592 0.8949 0.7806 1.0595 1.1138
##            1.2125 0.9661 0.9313 1.0259 0.8863 1.0428
## 
##   sigma:  0.1176
## 
##      AIC     AICc      BIC 
## 901.9431 925.5293 935.6247 
## 
## Training set error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE     ACF1
## Training set -173.7653 1179.871 965.1317 -1.613666 7.767323 0.2391307 0.246096
summary(ets_hawaiian) 
## ETS(M,N,N) 
## 
## Call:
## ets(y = hawaiian_window)
## 
##   Smoothing parameters:
##     alpha = 0.9999 
## 
##   Initial states:
##     l = 1975.8368 
## 
##   sigma:  0.1937
## 
##      AIC     AICc      BIC 
## 743.7838 744.3293 749.3974 
## 
## Training set error measures:
##                  ME     RMSE      MAE       MPE     MAPE      MASE         ACF1
## Training set 15.191 336.2452 239.0193 -1.012701 13.55208 0.4488625 -0.001138732

United Airlines

American Eagle

Hawaiian Airlines

Residual Analysis

residuals_ets_united <- residuals(ets_united)
fitted_ets_united <- fitted(ets_united)

residuals_ets_american <- residuals(ets_american)
fitted_ets_american <- fitted(ets_american)

residuals_ets_hawaiian <- residuals(ets_hawaiian)
fitted_ets_hawaiian <- fitted(ets_hawaiian)

par(mfrow = c(1, 3)) 
plot(residuals_ets_united, main = "United Airlines (ETS)", 
     ylab = "Residuals", xlab = "Time",col ='green')
plot(residuals_ets_american, main = "American Eagle Airlines (ETS)", 
     ylab = "Residuals", xlab = "Time", col ='blue')
plot(residuals_ets_hawaiian, main = "Hawaiian Airlines (ETS)", 
     ylab = "Residuals", xlab = "Time", col= 'red')

hist(residuals_ets_united, main = "United Airlines (ETS)", xlab = "Residuals")
hist(residuals_ets_american, main = "American Eagle Airlines ETS", xlab = "Residuals")
hist(residuals_ets_hawaiian, main = "Hawaiian Airlines (ETS)", xlab = "Residuals")

ggplot(data = NULL, aes(x = fitted_ets_united, y = residuals_ets_united)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: United Airlines",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = fitted_ets_american, y = residuals_ets_american)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: American Eagle ",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = fitted_ets_hawaiian, y = residuals_ets_hawaiian)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: Hawaiian Airlines",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

## Actual Vs Residual
ggplot(data = NULL, aes(x = united_window, y = residuals_ets_united)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: United Airlines",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = american_window, y = residuals_ets_american)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: American Eagle ",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = hawaiian_window, y = residuals_ets_hawaiian)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: Hawaiian Airlines",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

hw_united <- hw(united_window, h = 12)     
hw_american <- hw(american_window, h = 12) 
hw_hawaiian <- hw(hawaiian_window, h = 12) 

par(mfrow = c(1, 3))  

plot(hw_united, main = "Holt-Winters Forecast: United", xlab = "Year", ylab = "Complaints")
plot(hw_american, main = "Holt-Winters Forecast: American Eagle", xlab = "Year", ylab = "Complaints")
plot(hw_hawaiian, main = "Holt-Winters Forecast: Hawaiian ", xlab = "Year", ylab = "Complaints")

par(mfrow = c(1, 1))

Holt-Winters Forecast

United Airlines

American Eagle

Hawaiian Airlines

summary(hw_united)  
## 
## Forecast method: Holt-Winters' additive method
## 
## Model Information:
## Holt-Winters' additive method 
## 
## Call:
## hw(y = united_window, h = 12)
## 
##   Smoothing parameters:
##     alpha = 0.621 
##     beta  = 1e-04 
##     gamma = 1e-04 
## 
##   Initial states:
##     l = 32571.691 
##     b = -476.2188 
##     s = 8771.368 -6977.65 -3964.608 -5511.03 5243.736 3078.918
##            5014.77 -1386.432 -2520.716 -331.1463 -3010.162 1592.952
## 
##   sigma:  3370.045
## 
##       AIC      AICc       BIC 
##  980.1327 1000.5327 1011.9431 
## 
## Error measures:
##                     ME    RMSE     MAE      MPE    MAPE      MASE       ACF1
## Training set -30.65225 2751.63 1960.97 0.253576 11.1306 0.3630865 0.08283619
## 
## Forecasts:
##          Point Forecast       Lo 80     Hi 80       Lo 95    Hi 95
## Jan 2011     9912.59367   5593.7077 14231.480   3307.4276 16517.76
## Feb 2011     4832.39596   -251.7909  9916.583  -2943.1968 12607.99
## Mar 2011     7034.73097   1286.0396 12783.422  -1757.1339 15826.60
## Apr 2011     4368.42332  -1975.7289 10712.576  -5334.1203 14070.97
## May 2011     5026.68049  -1861.8172 11915.178  -5508.3676 15561.73
## Jun 2011    10951.66895   3558.6417 18344.696   -354.9906 22258.33
## Jul 2011     8539.56203    674.1553 16404.969  -3489.5395 20568.66
## Aug 2011    10227.75699   1916.6372 18538.877  -2483.0039 22938.52
## Sep 2011    -1002.60384  -9736.8537  7731.646 -14360.4863 12355.28
## Oct 2011       67.02262  -9070.9121  9204.957 -13908.2425 14042.29
## Nov 2011    -3422.17875 -12946.8257  6102.468 -17988.8692 11144.51
## Dec 2011    11849.34916   1952.9726 21745.726  -3285.8528 26984.55
summary(hw_american)  
## 
## Forecast method: Holt-Winters' additive method
## 
## Model Information:
## Holt-Winters' additive method 
## 
## Call:
## hw(y = american_window, h = 12)
## 
##   Smoothing parameters:
##     alpha = 0.5743 
##     beta  = 3e-04 
##     gamma = 0.0321 
## 
##   Initial states:
##     l = 24321.1432 
##     b = -270.2226 
##     s = 4446.341 -2396.847 -1678.507 -3156.506 1301.747 1997.55
##            2099.493 -264.0999 -509.9658 835.7922 -1184.309 -1490.689
## 
##   sigma:  2178.696
## 
##      AIC     AICc      BIC 
## 938.2576 958.6576 970.0680 
## 
## Error measures:
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -108.7539 1778.898 1433.417 -0.5826443 11.43462 0.3551579
##                   ACF1
## Training set 0.1264468
## 
## Forecasts:
##          Point Forecast     Lo 80     Hi 80      Lo 95    Hi 95
## Jan 2011       6754.584  3962.473  9546.695  2484.4187 11024.75
## Feb 2011       6340.152  3119.911  9560.393  1415.2180 11265.09
## Mar 2011       8176.599  4578.487 11774.711  2673.7618 13679.44
## Apr 2011       6599.022  2658.811 10539.232   572.9900 12625.05
## May 2011       6611.690  2356.517 10866.863   103.9644 13119.42
## Jun 2011       8851.045  4302.405 13399.685  1894.5003 15807.59
## Jul 2011       8274.570  3450.033 13099.106   896.0781 15653.06
## Aug 2011       7362.390  2276.668 12448.112  -415.5504 15140.33
## Sep 2011       2721.340 -2613.019  8055.698 -5436.8581 10879.54
## Oct 2011       3863.880 -1708.247  9436.006 -4657.9525 12385.71
## Nov 2011       2801.717 -2998.645  8602.079 -6069.1715 11672.61
## Dec 2011       9409.915  3389.765 15430.065   202.8896 18616.94
summary(hw_hawaiian)
## 
## Forecast method: Holt-Winters' additive method
## 
## Model Information:
## Holt-Winters' additive method 
## 
## Call:
## hw(y = hawaiian_window, h = 12)
## 
##   Smoothing parameters:
##     alpha = 0.9226 
##     beta  = 1e-04 
##     gamma = 1e-04 
## 
##   Initial states:
##     l = 2119.2169 
##     b = -7.342 
##     s = 104.2992 -136.8299 -3.4078 -143.5896 188.3205 519.1114
##            199.258 126.5693 18.7822 -231.2163 -328.0321 -313.2649
## 
##   sigma:  396.884
## 
##      AIC     AICc      BIC 
## 774.7851 795.1851 806.5956 
## 
## Error measures:
##                    ME     RMSE     MAE        MPE     MAPE      MASE
## Training set 18.08109 324.0544 242.455 -0.6423617 14.38428 0.4553146
##                     ACF1
## Training set 0.008432555
## 
## Forecasts:
##          Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## Jan 2011       2245.877 1737.2494 2754.504 1467.99837 3023.755
## Feb 2011       2223.701 1531.6485 2915.753 1165.29825 3282.103
## Mar 2011       2313.332 1477.1393 3149.525 1034.48562 3592.179
## Apr 2011       2555.966 1597.0352 3514.897 1089.40792 4022.524
## May 2011       2656.584 1588.9103 3724.257 1023.71826 4289.449
## Jun 2011       2722.070 1555.7287 3888.411  938.30502 4505.835
## Jul 2011       3034.575 1777.2662 4291.883 1111.68719 4957.462
## Aug 2011       2696.582 1354.4399 4038.725  643.95265 4749.212
## Sep 2011       2357.520  935.5796 3779.461  182.84972 4532.191
## Oct 2011       2490.342  992.8333 3987.850  200.10017 4780.584
## Nov 2011       2349.674  780.2168 3919.132  -50.60377 4749.952
## Dec 2011       2583.529  945.2646 4221.793   78.02005 5089.037

United Airlines

American Eagle

Hawaiian Airlines

Residual Analysis

residuals_hw_united <- residuals(hw_united)
fitted_hw_united <- fitted(hw_united)

residuals_hw_american <- residuals(hw_american)
fitted_hw_american <- fitted(hw_american)

residuals_hw_hawaiian <- residuals(hw_hawaiian)
fitted_hw_hawaiian <- fitted(hw_hawaiian)

par(mfrow = c(1, 3)) 
plot(residuals_hw_united, main = "United Airlines (/hw)", 
     ylab = "Residuals", xlab = "Time",col ='green')
plot(residuals_hw_american, main = "American Eagle Airlines (HW)", 
     ylab = "Residuals", xlab = "Time", col ='blue')
plot(residuals_hw_hawaiian, main = "Hawaiian Airlines (HW)", 
     ylab = "Residuals", xlab = "Time", col= 'red')

hist(residuals_hw_united, main = "United Airlines (HW)", xlab = "Residuals")
hist(residuals_hw_american, main = "American Eagle Airlines HW", xlab = "Residuals")
hist(residuals_hw_hawaiian, main = "Hawaiian Airlines (HW)", xlab = "Residuals")

ggplot(data = NULL, aes(x = fitted_hw_united, y = residuals_hw_united)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: United Airlines",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = fitted_hw_american, y = residuals_hw_american)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: American Eagle ",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = fitted_hw_hawaiian, y = residuals_hw_hawaiian)) +
  geom_point(color = "blue") + 
  labs(title = "Fitted vs Residuals: Hawaiian Airlines",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

## Actual Vs Residual
ggplot(data = NULL, aes(x = united_window, y = residuals_hw_united)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: United Airlines",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = american_window, y = residuals_hw_american)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: American Eagle ",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

ggplot(data = NULL, aes(x = hawaiian_window, y = residuals_hw_hawaiian)) +
  geom_point(color = "blue") + 
  labs(title = "Actual vs Residuals: Hawaiian Airlines",
       x = "Actual Values", y = "Residuals") +
  theme_minimal()
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

Accuracy

accuracy_naive_us <- accuracy(united_naive)
accuracy_naive_am <- accuracy(american_naive)
accuracy_naive_ha <- accuracy(hawaiian_naive)

accuracy_avg_us <- accuracy(united_sa)
accuracy_avg_am <- accuracy(american_sa)
accuracy_avg_ha <- accuracy(hawaiian_sa)

accuracy_ets_us <- accuracy(ets_united)
accuracy_ets_am <- accuracy(ets_american)
accuracy_ets_ha <- accuracy(ets_hawaiian)

accuracy_hw_us <- accuracy(hw_united)
accuracy_hw_am <- accuracy(hw_american)
accuracy_hw_ha <- accuracy(hw_hawaiian)

accuracy_data <- data.frame(
  Airline = rep(c("United", "American Eagle", "Hawaiian"), each = 4), # Repeat for each airline
  Model = rep(c("Naive", "Average", "ETS", "Holt-Winters"), 3),       # Repeat for each model
  ME = c(
    accuracy_naive_us["Training set", "ME"], accuracy_avg_us["Training set", "ME"], accuracy_ets_us["Training set", "ME"], accuracy_hw_us["Training set", "ME"],
    accuracy_naive_am["Training set", "ME"], accuracy_avg_am["Training set", "ME"], accuracy_ets_am["Training set", "ME"], accuracy_hw_am["Training set", "ME"],
    accuracy_naive_ha["Training set", "ME"], accuracy_avg_ha["Training set", "ME"], accuracy_ets_ha["Training set", "ME"], accuracy_hw_ha["Training set", "ME"]
  ),
  RMSE = c(
    accuracy_naive_us["Training set", "RMSE"], accuracy_avg_us["Training set", "RMSE"], accuracy_ets_us["Training set", "RMSE"], accuracy_hw_us["Training set", "RMSE"],
    accuracy_naive_am["Training set", "RMSE"], accuracy_avg_am["Training set", "RMSE"], accuracy_ets_am["Training set", "RMSE"], accuracy_hw_am["Training set", "RMSE"],
    accuracy_naive_ha["Training set", "RMSE"], accuracy_avg_ha["Training set", "RMSE"], accuracy_ets_ha["Training set", "RMSE"], accuracy_hw_ha["Training set", "RMSE"]
  ),
  MAE = c(
    accuracy_naive_us["Training set", "MAE"], accuracy_avg_us["Training set", "MAE"], accuracy_ets_us["Training set", "MAE"], accuracy_hw_us["Training set", "MAE"],
    accuracy_naive_am["Training set", "MAE"], accuracy_avg_am["Training set", "MAE"], accuracy_ets_am["Training set", "MAE"], accuracy_hw_am["Training set", "MAE"],
    accuracy_naive_ha["Training set", "MAE"], accuracy_avg_ha["Training set", "MAE"], accuracy_ets_ha["Training set", "MAE"], accuracy_hw_ha["Training set", "MAE"]
  ),
  MPE = c(
    accuracy_naive_us["Training set", "MPE"], accuracy_avg_us["Training set", "MPE"], accuracy_ets_us["Training set", "MPE"], accuracy_hw_us["Training set", "MPE"],
    accuracy_naive_am["Training set", "MPE"], accuracy_avg_am["Training set", "MPE"], accuracy_ets_am["Training set", "MPE"], accuracy_hw_am["Training set", "MPE"],
    accuracy_naive_ha["Training set", "MPE"], accuracy_avg_ha["Training set", "MPE"], accuracy_ets_ha["Training set", "MPE"], accuracy_hw_ha["Training set", "MPE"]
  ),
  MAPE = c(
    accuracy_naive_us["Training set", "MAPE"], accuracy_avg_us["Training set", "MAPE"], accuracy_ets_us["Training set", "MAPE"], accuracy_hw_us["Training set", "MAPE"],
    accuracy_naive_am["Training set", "MAPE"], accuracy_avg_am["Training set", "MAPE"], accuracy_ets_am["Training set", "MAPE"], accuracy_hw_am["Training set", "MAPE"],
    accuracy_naive_ha["Training set", "MAPE"], accuracy_avg_ha["Training set", "MAPE"], accuracy_ets_ha["Training set", "MAPE"], accuracy_hw_ha["Training set", "MAPE"]
  ),
  MASE = c(
    accuracy_naive_us["Training set", "MASE"], accuracy_avg_us["Training set", "MASE"], accuracy_ets_us["Training set", "MASE"], accuracy_hw_us["Training set", "MASE"],
    accuracy_naive_am["Training set", "MASE"], accuracy_avg_am["Training set", "MASE"], accuracy_ets_am["Training set", "MASE"], accuracy_hw_am["Training set", "MASE"],
    accuracy_naive_ha["Training set", "MASE"], accuracy_avg_ha["Training set", "MASE"], accuracy_ets_ha["Training set", "MASE"], accuracy_hw_ha["Training set", "MASE"]
  )
)

# Display the accuracy data frame
print(accuracy_data)
##           Airline        Model            ME      RMSE       MAE         MPE
## 1          United        Naive -5.823830e+02 6342.4118 4710.6383  -7.2628622
## 2          United      Average  4.414839e-12 7972.3744 6762.5868 -16.7322822
## 3          United          ETS -1.115725e+02 2197.5369 1593.7358  -1.0101378
## 4          United Holt-Winters -3.065225e+01 2751.6299 1960.9698   0.2535760
## 5  American Eagle        Naive -2.694468e+02 3357.8815 2489.9574  -4.6785274
## 6  American Eagle      Average  1.368979e-12 5259.4864 4316.8976 -14.3138043
## 7  American Eagle          ETS -1.737653e+02 1179.8710  965.1317  -1.6136663
## 8  American Eagle Holt-Winters -1.087539e+02 1778.8977 1433.4174  -0.5826443
## 9        Hawaiian        Naive  1.402128e+01  339.6493  242.6170  -1.1070565
## 10       Hawaiian      Average -4.736952e-15  479.3550  418.7552  -7.3905229
## 11       Hawaiian          ETS  1.519100e+01  336.2452  239.0193  -1.0127008
## 12       Hawaiian Holt-Winters  1.808109e+01  324.0544  242.4550  -0.6423617
##         MAPE      MASE
## 1  24.827234 0.8722058
## 2  38.749395 1.2521377
## 3   7.813287 0.2950907
## 4  11.130598 0.3630865
## 5  19.472247 0.6169369
## 6  34.652909 1.0695980
## 7   7.767323 0.2391307
## 8  11.434619 0.3551579
## 9  13.767841 0.4556188
## 10 25.142269 0.7863948
## 11 13.552079 0.4488625
## 12 14.384280 0.4553146
# Optional: Rank models based on each metric
accuracy_table <- accuracy_data %>%
  group_by(Airline) %>%
  mutate(
    ME_Rank = rank(ME),
    RMSE_Rank = rank(RMSE),
    MAE_Rank = rank(MAE),
    MPE_Rank = rank(MPE),
    MAPE_Rank = rank(MAPE),
    MASE_Rank = rank(MASE)
  )

# Display the ranked table
print(accuracy_table)
## # A tibble: 12 × 14
## # Groups:   Airline [3]
##    Airline     Model        ME  RMSE   MAE     MPE  MAPE  MASE ME_Rank RMSE_Rank
##    <chr>       <chr>     <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl>   <dbl>     <dbl>
##  1 United      Naive -5.82e+ 2 6342. 4711.  -7.26  24.8  0.872       1         3
##  2 United      Aver…  4.41e-12 7972. 6763. -16.7   38.7  1.25        4         4
##  3 United      ETS   -1.12e+ 2 2198. 1594.  -1.01   7.81 0.295       2         1
##  4 United      Holt… -3.07e+ 1 2752. 1961.   0.254 11.1  0.363       3         2
##  5 American E… Naive -2.69e+ 2 3358. 2490.  -4.68  19.5  0.617       1         3
##  6 American E… Aver…  1.37e-12 5259. 4317. -14.3   34.7  1.07        4         4
##  7 American E… ETS   -1.74e+ 2 1180.  965.  -1.61   7.77 0.239       2         1
##  8 American E… Holt… -1.09e+ 2 1779. 1433.  -0.583 11.4  0.355       3         2
##  9 Hawaiian    Naive  1.40e+ 1  340.  243.  -1.11  13.8  0.456       2         3
## 10 Hawaiian    Aver… -4.74e-15  479.  419.  -7.39  25.1  0.786       1         4
## 11 Hawaiian    ETS    1.52e+ 1  336.  239.  -1.01  13.6  0.449       3         2
## 12 Hawaiian    Holt…  1.81e+ 1  324.  242.  -0.642 14.4  0.455       4         1
## # ℹ 4 more variables: MAE_Rank <dbl>, MPE_Rank <dbl>, MAPE_Rank <dbl>,
## #   MASE_Rank <dbl>

ETS is consistently the best-performing model across all three airlines.

Forecast of baggage complaints

par(mfrow = c(1, 3))

plot(forecast(ets_united, h = 12), main = "ETS Forecast: United Airlines", xlab = "Year", ylab = "Complaints")

plot(forecast(ets_american, h = 12), main = "ETS Forecast: American Eagle", xlab = "Year", ylab = "Complaints")

plot(forecast(ets_hawaiian, h = 12), main = "ETS Forecast: Hawaiian Airlines", xlab = "Year", ylab = "Complaints")

Conclusion

United Airlines

American Eagle

Hawaiian Airlines

Decision Based on Analysis

  1. United Airlines: Focus on Peak Travel Seasons: United should prioritize improving baggage handling during high-complaint months like December and July. The seasonal pattern is strong, so targeted measures during peak periods will have the most impact on reducing complaints.
  2. American Eagle: Sustain Gradual Improvements: With complaints stabilizing and a slight downward trend, American Eagle should continue its improvement strategies while preparing for occasional spikes, especially in summer months.
  3. Hawaiian Airlines: Maintain Current Operations: Hawaiian Airlines demonstrates consistent performance with minimal seasonal changes. The focus should remain on sustaining this stability while looking for opportunities to further optimize operations.